import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'permission_logic.dart';

/// 权限授权页面视图 - Permission Authorization View
///
/// Android平台首次启动时显示的权限授权页面
/// Permission authorization page displayed on first launch for Android platform
class PermissionView extends StatelessWidget {
  const PermissionView({super.key});

  @override
  Widget build(BuildContext context) {
    // GetBuilder作为最外层包裹Widget - GetBuilder as the outermost wrapper widget
    // 每个View中只能有一个GetBuilder - Only one GetBuilder per View
    return GetBuilder<PermissionLogic>(
      init: PermissionLogic(),
      builder: (logic) {
        return Scaffold(
          backgroundColor: Colors.white,
          body: SafeArea(
            child: Padding(
              padding: const EdgeInsets.all(24.0),
              child: Column(
                children: [
                  // 顶部图标 - Top Icon
                  const SizedBox(height: 60),
                  Container(
                    width: 100,
                    height: 100,
                    decoration: BoxDecoration(
                      color: Colors.blue.shade50,
                      borderRadius: BorderRadius.circular(50),
                    ),
                    child: Icon(
                      Icons.security,
                      size: 50,
                      color: Colors.blue,
                    ),
                  ),

                  const SizedBox(height: 32),

                  // 标题 - Title
                  const Text(
                    '权限授权',
                    style: TextStyle(
                      fontSize: 24,
                      fontWeight: FontWeight.bold,
                      color: Colors.black87,
                    ),
                  ),

                  const SizedBox(height: 16),

                  // 权限说明 - Permission Description
                  const Text(
                    '为了更好地为您提供服务，应用需要获取以下权限：',
                    style: TextStyle(
                      fontSize: 16,
                      color: Colors.black54,
                    ),
                    textAlign: TextAlign.center,
                  ),

                  const SizedBox(height: 32),

                  // 权限列表 - Permission List
                  Expanded(
                    child: ListView(
                      children: [
                        _buildPermissionItem(
                          icon: Icons.storage,
                          title: '存储权限',
                          description: '用于保存和读取 Prompt 数据文件',
                        ),
                        _buildPermissionItem(
                          icon: Icons.folder,
                          title: '文件访问权限',
                          description: '用于导入和导出 Prompt 文件',
                        ),
                        _buildPermissionItem(
                          icon: Icons.notifications,
                          title: '通知权限',
                          description: '用于发送重要提醒和更新通知',
                        ),
                      ],
                    ),
                  ),

                  // 底部按钮 - Bottom Buttons
                  const SizedBox(height: 32),
                  Row(
                    children: [
                      // 不同意按钮 - Disagree Button
                      Expanded(
                        child: OutlinedButton(
                          onPressed: logic.onDisagree,
                          style: OutlinedButton.styleFrom(
                            padding: const EdgeInsets.symmetric(vertical: 16),
                            side: BorderSide(color: Colors.grey.shade400),
                            shape: RoundedRectangleBorder(
                              borderRadius: BorderRadius.circular(8),
                            ),
                          ),
                          child: const Text(
                            '不同意',
                            style: TextStyle(
                              fontSize: 16,
                              color: Colors.black54,
                            ),
                          ),
                        ),
                      ),

                      const SizedBox(width: 16),

                      // 同意按钮 - Agree Button
                      Expanded(
                        child: ElevatedButton(
                          onPressed: logic.onAgree,
                          style: ElevatedButton.styleFrom(
                            backgroundColor: Colors.blue,
                            padding: const EdgeInsets.symmetric(vertical: 16),
                            shape: RoundedRectangleBorder(
                              borderRadius: BorderRadius.circular(8),
                            ),
                          ),
                          child: const Text(
                            '同意',
                            style: TextStyle(
                              fontSize: 16,
                              color: Colors.white,
                            ),
                          ),
                        ),
                      ),
                    ],
                  ),

                  const SizedBox(height: 16),

                  // 隐私说明 - Privacy Notice
                  Text(
                    '我们承诺严格保护您的隐私，不会收集任何个人敏感信息',
                    style: TextStyle(
                      fontSize: 12,
                      color: Colors.grey.shade600,
                    ),
                    textAlign: TextAlign.center,
                  ),
                ],
              ),
            ),
          ),
        );
      },
    );
  }

  /// 构建权限项 - Build Permission Item
  Widget _buildPermissionItem({
    required IconData icon,
    required String title,
    required String description,
  }) {
    return Container(
      margin: const EdgeInsets.only(bottom: 16),
      padding: const EdgeInsets.all(16),
      decoration: BoxDecoration(
        color: Colors.grey.shade50,
        borderRadius: BorderRadius.circular(12),
        border: Border.all(color: Colors.grey.shade200),
      ),
      child: Row(
        children: [
          // 图标 - Icon
          Container(
            width: 40,
            height: 40,
            decoration: BoxDecoration(
              color: Colors.blue.shade100,
              borderRadius: BorderRadius.circular(20),
            ),
            child: Icon(
              icon,
              size: 20,
              color: Colors.blue,
            ),
          ),

          const SizedBox(width: 16),

          // 文本信息 - Text Information
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  title,
                  style: const TextStyle(
                    fontSize: 16,
                    fontWeight: FontWeight.w600,
                    color: Colors.black87,
                  ),
                ),
                const SizedBox(height: 4),
                Text(
                  description,
                  style: TextStyle(
                    fontSize: 14,
                    color: Colors.grey.shade600,
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}